<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/25 0025
 * Time: 9:19
 */
namespace app\api\controller;

use app\api\model\Api;
use app\api\model\JWT;
use think\App;
use think\Controller;
use think\Db;
use app\api\model\Role as RoleModel;

/**
 * @title 首页
 * @description 接口说明
 */
class Index extends Api
{
    /**
     * @title 首页
     * @description 接口说明
     * @header name:flag require:1 default: desc:手机设备号
     * @author 开发者
     * @url /api/Index/index
     * @method POST
     * 
     * @param name:year type:int require:1 default: other: desc:年份
     * @param name:month type:int require:1 default: other: desc:月份
     * @param name:banquet type:int require:1 default: other: desc:宴会厅id
     *
     *
     * @return list:列表@
     * @list id:宴会厅id name:宴会厅名称 order:列表@
     * @order id:id begin_year:开始年份 begin_month:开始月份 begin_day:开始天数 begin_night:1中午2晚上 type:1潜客2预定 is_meeting:1会议2宴会 day:年月日 bid:宴会厅id
     * 
     */
    public function index(){
        if(!input('year')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        if(!input('month')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        
        $year = input('year');
        $month = input('month');
        $banquets = input('banquet');
        $page = input('page')??1;
        $user = $this->user;
        // 宴会厅
        $where[] = ['is_hidden','=','1'];
        $where[] = ['hid','=',$user['hid']];
        $where[] = ['is_del','=',1];
        $banquet = db::name('banquet')->where($where)->field('id,name')->select();

        $wheres[] = ['begin_year','=',$year];
        $wheres[] = ['begin_month','=',$month];
        
        $wheres[] = ['hid','=',$user['hid']];
        $wheres[] = ['type','neq',3];
        $wheres[] = ['is_del','=',2];
        $wheres[] = ['is_meeting','=',2];

        // $wheres[] = ['id','=',241];


        // print_r($wheres);die;

        $scheduled = db::name('scheduled')->where($wheres)
        ->field('id,begin_year,begin_month,begin_day,begin_night,end_year,end_month,end_day,end_night,type,is_meeting,bid')->select();
        $wheres[1][0] = 'end_month';
        $wheres[0][0] = 'end_year';
        $wheres[5][2] = '1';

        $scheduleds = db::name('scheduled')->where($wheres)
        ->field('id,begin_year,begin_month,begin_day,begin_night,end_year,end_month,end_day,end_night,type,is_meeting,bid')->select();
        $scheduled = array_merge($scheduleds,$scheduled);
       
        $res = $this->group_same_key($scheduled,'bid');
        if($scheduled){
            foreach($banquet as $k=>$v){
                foreach($res as $ks=>$vs){
                    if($ks == $v['id']){
                        $banquet[$k]['order'] = $vs;
                    }
                }
            }
            foreach($banquet as $kb => $vb){
                $newArrd = [];
                if(isset($vb['order'])){
                    $order = $this->group_same_key($vb['order'],'begin_day');
                    foreach($order as $ok=>$ov){
                        $type = $this->group_same_key($ov,'type');
                        $type_count = count($type);
                        // 处理之后的数据
                        if($type_count == 2){
                            if(isset($type[1])){
                                $count = count($type[1]);
                                for ($i=0; $i < $count; $i++) {
                                    if($type[1][$i]['begin_night'] == $type[2][0]['begin_night']){
                                    unset($type[1][$i]);
                                    }
                                }
                                $count = count($type[1]);
                                $aa = $count - 1;
                                if($count > 1){
                                    for ($i=0; $i < $count; $i++) {
                                        if($i == $aa){
                                            break;
                                        }else{
                                            unset($type[1][$i]);
                                        }
                                    }
                                }
                            }
                            // 修改
                        }elseif($type_count == 1){
                            if(isset($type[1])){
                                $begin_nights = $this->group_same_key($type[1],'begin_night');
                                
                                if(isset($begin_nights[1])){
                                    $count = count($begin_nights[1]);
                                    $aa = $count - 1;
                                    if($count > 1){
                                        for ($i=0; $i < $count; $i++) {
                                            if($i == $aa){
                                                break;
                                            }else{
                                                unset($begin_nights[1][$i]);
                                            }
                                        }
                                    }
                                }
                                if(isset($begin_nights[2])){
                                    $count = count($begin_nights[2]);
                                    $aa = $count - 1;
                                    if($count > 1){
                                        for ($i=0; $i < $count; $i++) {
                                            if($i == $aa){
                                                break;
                                            }else{
                                                unset($begin_nights[2][$i]);
                                            }
                                        }
                                    }
                                }
                                $type = $begin_nights;
                            }
                        }
                        $newArrd[] = $type;
                        $type = [];
                    }
                    $yu = [];
                    foreach ($newArrd as $fk => $newArr) {
                        foreach($newArr as $kn =>$vs){
                            foreach ($vs as $vk => $vn) {
                                if($vn['is_meeting']  == 2 && $vn['type'] == 2){
                                    $yu[] = $vn;
                                }
                                
                            }
                        }
                    }
                    // 模拟数据
                    foreach ($newArrd as $fk => $newArr) {
                        foreach($newArr as $kn =>$vs){
                            foreach ($vs as $vk => $vn) {
                                if($vn['is_meeting'] == 1){
                                    $begin_time = $vn['begin_year'] .'-'. $vn['begin_month'].'-'. $vn['begin_day'];
                                    $end_time = $vn['end_year'] .'-'. $vn['end_month'].'-'. $vn['end_day'];
                                    $begin_night = $vn['begin_night'];
                                    $end_night = $vn['end_night'];
                
                                    $one = strtotime($begin_time);
                                    $tow = strtotime($end_time);
                                    $cle = $tow - $one; //得出时间戳差值
                                    $d = ceil($cle/3600/24);
                                    if($yu){
                                        foreach ($yu as $yk => $yv) {
                                            $y_begin =  $yv['begin_year'] .'-'. $yv['begin_month'].'-'. $yv['begin_day'];
                                            $y_begin = strtotime($y_begin);
                                            // 5-8 1      5-6  2                    5-8
                                            if($yv['bid'] == $vn['bid']){
                                                if($y_begin >= $one && $y_begin <= $tow){
                                                    if($y_begin == $one){
                                                        if($yv['begin_night'] == 1 && $begin_night == 2){
                                                            if($d == 0){
                                                                if($begin_night != $end_night){
                                                                    $newArrs[] =[
                                                                        'id'=>$vn['id'],
                                                                        'begin_year'=>$vn['begin_year'],
                                                                        'begin_month'=>$vn['begin_month'],
                                                                        'begin_day'=>$vn['begin_day'],
                                                                        'begin_night'=>$vn['end_night'],
                                                                        'type'=>$vn['type'],
                                                                        'is_meeting'=>$vn['is_meeting'],
                                                                        'bid'=>$vn['bid'],
                                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                                    ];
                                                                }else{
                                                                    $newArrs =[];
                                                                    unset($newArr[$kn]['end_year']);
                                                                    unset($newArr[$kn]['end_month']);
                                                                    unset($newArr[$kn]['end_day']);
                                                                    unset($newArr[$kn]['end_night']);
                                                                }
                                                            }elseif($d > 0){
                                                                // 本月天数
                                                                $days = date('t', strtotime($vn['begin_year'] .'-'. $vn['begin_month'].'-'. '1'));
                                                                $begin_days = $vn['begin_day'];
                                
                                                                if($vn['begin_month'] == $vn['end_month']){
                                                                    if($begin_night == 1){
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$vn['begin_day'],
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                
                                                                        ];
                                                                    }
                                                                    // $a = 1;
                                                                    for ($i=1; $i <=$d; $i++) {
                                                                        $a = $vn['begin_day'] + $i;
                                                                        if($a < 10){
                                                                            $as = '0' . $a;
                                                                        }
                                                                        if($a == $vn['end_day']){
                                                                            if($end_night == 1){
                                                                                $newArrs[] =[
                                                                                    'id'=>$vn['id'],
                                                                                    'begin_year'=>$vn['begin_year'],
                                                                                    'begin_month'=>$vn['begin_month'],
                                                                                    'begin_day'=>$as,
                                                                                    'begin_night'=>1,
                                                                                    'type'=>$vn['type'],
                                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                                    'bid'=>$vn['bid'],
                                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                        
                                                                                ];
                                                                            }else{
                                                                                $newArrs[] =[
                                                                                    'id'=>$vn['id'],
                                                                                    'begin_year'=>$vn['begin_year'],
                                                                                    'begin_month'=>$vn['begin_month'],
                                                                                    'begin_day'=>$as,
                                                                                    'begin_night'=>1,
                                                                                    'type'=>$vn['type'],
                                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                                    'bid'=>$vn['bid'],
                                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                        
                                                                                ];
                                                                                $newArrs[] =[
                                                                                    'id'=>$vn['id'],
                                                                                    'begin_year'=>$vn['begin_year'],
                                                                                    'begin_month'=>$vn['begin_month'],
                                                                                    'begin_day'=>$as,
                                                                                    'begin_night'=>2,
                                                                                    'type'=>$vn['type'],
                                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                                    'bid'=>$vn['bid'],
                                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                        
                                                                                ];
                                                                            }
                                                                        }else{
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>1,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                    
                                                                            ];
                                                                            
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>2,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                    
                                                                            ];
                                                                        }
                                                                        
                                                                        $a++;
                                                                    }
                                                                }elseif($vn['begin_month'] != $vn['end_month']){
                                                                    if($begin_night == 1){
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$vn['begin_day'],
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                                        ];
                                                                    }
                                                                    $a = 1;
                                                                    for ($i=1; $i <=$d; $i++) {
                                                                        $day = $vn['begin_day'] + $i;
                                
                                                                        if($day > $days){
                                                                            if($a < 10){
                                                                                $as = '0' . $a;
                                                                            }
                                                                            // $as = strval($a);
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['end_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>1,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                                
                                                                            ];
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['end_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>2,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                                
                                                                            ];
                                                                            $a++;
                                                                        }else{
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>strval($vn['begin_day'] + $i),
                                                                                'begin_night'=>1,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
                                
                                                                            ];
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>strval($vn['begin_day'] + $i),
                                                                                'begin_night'=>2,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
                                
                                                                            ];
                                                                        }
                                                                    }
                                                                    foreach ($newArrs as $nk => $nv) {
                                                                        if($month != $nv['begin_month']){
                                                                            unset($newArrs[$nk]);
                                                                        }
                                                                    }
                                                                }
                                                                $vn['day'] = $vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day'];
                                                                unset($vn['end_year']);
                                                                unset($vn['end_month']);
                                                                unset($vn['end_day']);
                                                                unset($vn['end_night']);
                                                            }
                                                        }elseif($yu['begin_night'] == 2 && $begin_night == 1){
                                                            $newArrs = [];
                                                        }elseif($yu['begin_night'] == 1 && $begin_night == 1){
                                                            $newArrs = [];
                                                        }elseif($yu['begin_night'] == 2 && $begin_night == 2){
                                                            $newArrs = [];
                                                        }
                                                    }else{
                                                        unset($newArrd[$fk][$kn][$vk]);
                                                        $newArrs = [];
                                                    }
                                                    if($y_begin == $tow){
                                                        if($yv['begin_night'] == 1 && $end_night == 2){
                                                            $newArrs = [];

                                                        }elseif($yu['begin_night'] == 2 && $end_night == 1){
                                                            if($d == 0){
                                                                if($begin_night != $end_night){
                                                                    $newArrs[] =[
                                                                        'id'=>$vn['id'],
                                                                        'begin_year'=>$vn['begin_year'],
                                                                        'begin_month'=>$vn['begin_month'],
                                                                        'begin_day'=>$vn['begin_day'],
                                                                        'begin_night'=>$vn['end_night'],
                                                                        'type'=>$vn['type'],
                                                                        'is_meeting'=>$vn['is_meeting'],
                                                                        'bid'=>$vn['bid'],
                                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                                    ];
                                                                }else{

                                                                    $newArrs =[];
                                                                    unset($newArr[$kn]['end_year']);
                                                                    unset($newArr[$kn]['end_month']);
                                                                    unset($newArr[$kn]['end_day']);
                                                                    unset($newArr[$kn]['end_night']);
                                                                }
                                                            }elseif($d > 0){
                                                                // 本月天数
                                                                $days = date('t', strtotime($vn['begin_year'] .'-'. $vn['begin_month'].'-'. '1'));
                                                                $begin_days = $vn['begin_day'];
                                
                                                                if($vn['begin_month'] == $vn['end_month']){
                                                                    if($begin_night == 1){
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$vn['begin_day'],
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                
                                                                        ];
                                                                    }
                                                                    // $a = 1;
                                                                    for ($i=1; $i <=$d; $i++) {
                                                                        $a = $vn['begin_day'] + $i;
                                                                        if($a < 10){
                                                                            $as = '0' . $a;
                                                                        }
                                                                        if($a == $vn['end_day']){
                                                                            if($end_night == 1){
                                                                                $newArrs[] =[
                                                                                    'id'=>$vn['id'],
                                                                                    'begin_year'=>$vn['begin_year'],
                                                                                    'begin_month'=>$vn['begin_month'],
                                                                                    'begin_day'=>$as,
                                                                                    'begin_night'=>1,
                                                                                    'type'=>$vn['type'],
                                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                                    'bid'=>$vn['bid'],
                                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                        
                                                                                ];
                                                                            }else{
                                                                                $newArrs[] =[
                                                                                    'id'=>$vn['id'],
                                                                                    'begin_year'=>$vn['begin_year'],
                                                                                    'begin_month'=>$vn['begin_month'],
                                                                                    'begin_day'=>$as,
                                                                                    'begin_night'=>1,
                                                                                    'type'=>$vn['type'],
                                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                                    'bid'=>$vn['bid'],
                                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                        
                                                                                ];
                                                                                $newArrs[] =[
                                                                                    'id'=>$vn['id'],
                                                                                    'begin_year'=>$vn['begin_year'],
                                                                                    'begin_month'=>$vn['begin_month'],
                                                                                    'begin_day'=>$as,
                                                                                    'begin_night'=>2,
                                                                                    'type'=>$vn['type'],
                                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                                    'bid'=>$vn['bid'],
                                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                        
                                                                                ];
                                                                            }
                                                                        }else{
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>1,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                    
                                                                            ];
                                                                            
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>2,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                    
                                                                            ];
                                                                        }
                                                                        
                                                                        $a++;
                                                                    }
                                                                }elseif($vn['begin_month'] != $vn['end_month']){
                                                                    if($begin_night == 1){
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$vn['begin_day'],
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                                        ];
                                                                    }
                                                                    $a = 1;
                                                                    for ($i=1; $i <=$d; $i++) {
                                                                        $day = $vn['begin_day'] + $i;
                                
                                                                        if($day > $days){
                                                                            if($a < 10){
                                                                                $as = '0' . $a;
                                                                            }
                                                                            // $as = strval($a);
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['end_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>1,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                                
                                                                            ];
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['end_month'],
                                                                                'begin_day'=>$as,
                                                                                'begin_night'=>2,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                                
                                                                            ];
                                                                            $a++;
                                                                        }else{
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>strval($vn['begin_day'] + $i),
                                                                                'begin_night'=>1,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
                                
                                                                            ];
                                                                            $newArrs[] =[
                                                                                'id'=>$vn['id'],
                                                                                'begin_year'=>$vn['begin_year'],
                                                                                'begin_month'=>$vn['begin_month'],
                                                                                'begin_day'=>strval($vn['begin_day'] + $i),
                                                                                'begin_night'=>2,
                                                                                'type'=>$vn['type'],
                                                                                'is_meeting'=>$vn['is_meeting'],
                                                                                'bid'=>$vn['bid'],
                                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
                                
                                                                            ];
                                                                        }
                                                                    }
                                                                    foreach ($newArrs as $nk => $nv) {
                                                                        if($month != $nv['begin_month']){
                                                                            unset($newArrs[$nk]);
                                                                        }
                                                                    }
                                                                }
                                                                $vn['day'] = $vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day'];
                                                                unset($vn['end_year']);
                                                                unset($vn['end_month']);
                                                                unset($vn['end_day']);
                                                                unset($vn['end_night']);
                                                            }
                                                        }elseif($yu['begin_night'] == 1 && $begin_night == 1){
                                                            $newArrs = [];

                                                        }elseif($yu['begin_night'] == 2 && $begin_night == 2){
                                                            $newArrs = [];

                                                        }
                                                    }else{
                                                        unset($newArrd[$fk][$kn][$vk]);
                                                
                                                        $newArrs = [];

                                                    }

                                                }else{
                                                    if($d == 0){
                                                        if($begin_night != $end_night){
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['begin_year'],
                                                                'begin_month'=>$vn['begin_month'],
                                                                'begin_day'=>$vn['begin_day'],
                                                                'begin_night'=>$vn['end_night'],
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                            ];
                                                        }else{
                                                            $newArrs =[];
                                                            unset($newArr[$kn]['end_year']);
                                                            unset($newArr[$kn]['end_month']);
                                                            unset($newArr[$kn]['end_day']);
                                                            unset($newArr[$kn]['end_night']);
                                                            
                                                        }
                                                    }elseif($d > 0){
                                                        // 本月天数
                                                        $days = date('t', strtotime($vn['begin_year'] .'-'. $vn['begin_month'].'-'. '1'));
                                                        $begin_days = $vn['begin_day'];
                        
                                                        if($vn['begin_month'] == $vn['end_month']){
                                                            if($begin_night == 1){
                                                                $newArrs[] =[
                                                                    'id'=>$vn['id'],
                                                                    'begin_year'=>$vn['begin_year'],
                                                                    'begin_month'=>$vn['begin_month'],
                                                                    'begin_day'=>$vn['begin_day'],
                                                                    'begin_night'=>2,
                                                                    'type'=>$vn['type'],
                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                    'bid'=>$vn['bid'],
                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                        
                                                                ];
                                                            }
                                                            // $a = 1;
                                                            for ($i=1; $i <=$d; $i++) {
                                                                $a = $vn['begin_day'] + $i;
                                                                if($a < 10){
                                                                    $as = '0' . $a;
                                                                }else{
                                                                    $as = strval($a);
                                                                }
                                                                if($a == $vn['end_day']){
                                                                    if($end_night == 1){
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>1,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                
                                                                        ];
                                                                    }else{
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>1,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                
                                                                        ];
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['begin_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                                
                                                                        ];
                                                                    }
                                                                }else{
                                                                    $newArrs[] =[
                                                                        'id'=>$vn['id'],
                                                                        'begin_year'=>$vn['begin_year'],
                                                                        'begin_month'=>$vn['begin_month'],
                                                                        'begin_day'=>$as,
                                                                        'begin_night'=>1,
                                                                        'type'=>$vn['type'],
                                                                        'is_meeting'=>$vn['is_meeting'],
                                                                        'bid'=>$vn['bid'],
                                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                            
                                                                    ];
                                                                    
                                                                    $newArrs[] =[
                                                                        'id'=>$vn['id'],
                                                                        'begin_year'=>$vn['begin_year'],
                                                                        'begin_month'=>$vn['begin_month'],
                                                                        'begin_day'=>$as,
                                                                        'begin_night'=>2,
                                                                        'type'=>$vn['type'],
                                                                        'is_meeting'=>$vn['is_meeting'],
                                                                        'bid'=>$vn['bid'],
                                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                            
                                                                    ];
                                                                }
                                                                
                                                                $a++;
                                                            }
                                                        }elseif($vn['begin_month'] != $vn['end_month']){
                                                            if($begin_night == 1){
                                                                $newArrs[] =[
                                                                    'id'=>$vn['id'],
                                                                    'begin_year'=>$vn['begin_year'],
                                                                    'begin_month'=>$vn['begin_month'],
                                                                    'begin_day'=>$vn['begin_day'],
                                                                    'begin_night'=>2,
                                                                    'type'=>$vn['type'],
                                                                    'is_meeting'=>$vn['is_meeting'],
                                                                    'bid'=>$vn['bid'],
                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                                ];
                                                            }
                                                           
                                                            $a = 1;
                                                            for ($i=1; $i <=$d; $i++) {
                                                                $day = $vn['begin_day'] + $i;
                        
                                                                if($day > $days){
                                                                    if($vn['begin_month'] == 12){
                                                                        if($a < 10){
                                                                            $as = '0' . $a;
                                                                        }
                                                                        // $as = strval($a);
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['end_year'],
                                                                            'begin_month'=>$vn['end_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>1,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['end_year'] . '-' . $vn['end_month'] . '-' . $as
                            
                                                                        ];
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['end_year'],
                                                                            'begin_month'=>$vn['end_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                        'day'=>$vn['end_year'] . '-' . $vn['end_month'] . '-' . $as
                            
                                                                        ];
                                                                        $a++;
            
                                                                    }else{
                                                                        if($a < 10){
                                                                            $as = '0' . $a;
                                                                        }
                                                                        // $as = strval($a);
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['end_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>1,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                            'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                            
                                                                        ];
                                                                        $newArrs[] =[
                                                                            'id'=>$vn['id'],
                                                                            'begin_year'=>$vn['begin_year'],
                                                                            'begin_month'=>$vn['end_month'],
                                                                            'begin_day'=>$as,
                                                                            'begin_night'=>2,
                                                                            'type'=>$vn['type'],
                                                                            'is_meeting'=>$vn['is_meeting'],
                                                                            'bid'=>$vn['bid'],
                                                                        'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                            
                                                                        ];
                                                                        $a++;
                                                                    }
                                                                   
                                                                }else{
                                                                    $newArrs[] =[
                                                                        'id'=>$vn['id'],
                                                                        'begin_year'=>$vn['begin_year'],
                                                                        'begin_month'=>$vn['begin_month'],
                                                                        'begin_day'=>strval($vn['begin_day'] + $i),
                                                                        'begin_night'=>1,
                                                                        'type'=>$vn['type'],
                                                                        'is_meeting'=>$vn['is_meeting'],
                                                                        'bid'=>$vn['bid'],
                                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
                        
                                                                    ];
                                                                    $newArrs[] =[
                                                                        'id'=>$vn['id'],
                                                                        'begin_year'=>$vn['begin_year'],
                                                                        'begin_month'=>$vn['begin_month'],
                                                                        'begin_day'=>strval($vn['begin_day'] + $i),
                                                                        'begin_night'=>2,
                                                                        'type'=>$vn['type'],
                                                                        'is_meeting'=>$vn['is_meeting'],
                                                                        'bid'=>$vn['bid'],
                                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
                        
                                                                    ];
                                                                }
                                                            }
                                                            foreach ($newArrs as $nk => $nv) {
                                                                if($month != $nv['begin_month']){
                                                                    unset($newArrs[$nk]);
                                                                }
                                                            }
                                                        }
                                                        
                                                        $vn['day'] = $vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day'];
                                                        unset($vn['end_year']);
                                                        unset($vn['end_month']);
                                                        unset($vn['end_day']);
                                                        unset($vn['end_night']);
                                                        // $newArrs = [];
                                                    }
                                                }
                                            }
                                        }
                                    }else{
                                      
                                        if($d == 0){
                                            if($begin_night != $end_night){
                                                $newArrs[] =[
                                                    'id'=>$vn['id'],
                                                    'begin_year'=>$vn['begin_year'],
                                                    'begin_month'=>$vn['begin_month'],
                                                    'begin_day'=>$vn['begin_day'],
                                                    'begin_night'=>$vn['end_night'],
                                                    'type'=>$vn['type'],
                                                    'is_meeting'=>$vn['is_meeting'],
                                                    'bid'=>$vn['bid'],
                                                    'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                ];
                                            }else{
                                                $newArrs =[];
                                                unset($newArr[$kn]['end_year']);
                                                unset($newArr[$kn]['end_month']);
                                                unset($newArr[$kn]['end_day']);
                                                unset($newArr[$kn]['end_night']);
                                                
                                            }
                                        }elseif($d > 0){
                                            // 本月天数
                                            $days = date('t', strtotime($vn['begin_year'] .'-'. $vn['begin_month'].'-'. '1'));
                                            $begin_days = $vn['begin_day'];
            
                                            if($vn['begin_month'] == $vn['end_month']){
                                                if($begin_night == 1){
                                                    $newArrs[] =[
                                                        'id'=>$vn['id'],
                                                        'begin_year'=>$vn['begin_year'],
                                                        'begin_month'=>$vn['begin_month'],
                                                        'begin_day'=>$vn['begin_day'],
                                                        'begin_night'=>2,
                                                        'type'=>$vn['type'],
                                                        'is_meeting'=>$vn['is_meeting'],
                                                        'bid'=>$vn['bid'],
                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
            
                                                    ];
                                                }
                                                // $a = 1;
                                                for ($i=1; $i <=$d; $i++) {
                                                    $a = $vn['begin_day'] + $i;
                                                    if($a < 10){
                                                        $as = '0' . $a;
                                                    }else{
                                                        $as = strval($a);
                                                    }
                                                    if($a == $vn['end_day']){
                                                        if($end_night == 1){
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['begin_year'],
                                                                'begin_month'=>$vn['begin_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>1,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                    
                                                            ];
                                                        }else{
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['begin_year'],
                                                                'begin_month'=>$vn['begin_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>1,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                    
                                                            ];
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['begin_year'],
                                                                'begin_month'=>$vn['begin_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>2,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                                'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                    
                                                            ];
                                                        }
                                                    }else{
                                                        $newArrs[] =[
                                                            'id'=>$vn['id'],
                                                            'begin_year'=>$vn['begin_year'],
                                                            'begin_month'=>$vn['begin_month'],
                                                            'begin_day'=>$as,
                                                            'begin_night'=>1,
                                                            'type'=>$vn['type'],
                                                            'is_meeting'=>$vn['is_meeting'],
                                                            'bid'=>$vn['bid'],
                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                
                                                        ];
                                                        
                                                        $newArrs[] =[
                                                            'id'=>$vn['id'],
                                                            'begin_year'=>$vn['begin_year'],
                                                            'begin_month'=>$vn['begin_month'],
                                                            'begin_day'=>$as,
                                                            'begin_night'=>2,
                                                            'type'=>$vn['type'],
                                                            'is_meeting'=>$vn['is_meeting'],
                                                            'bid'=>$vn['bid'],
                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $as
                
                                                        ];
                                                    }
                                                    
                                                    $a++;
                                                }
                                            }elseif($vn['begin_month'] != $vn['end_month']){
                                                if($begin_night == 1){
                                                    $newArrs[] =[
                                                        'id'=>$vn['id'],
                                                        'begin_year'=>$vn['begin_year'],
                                                        'begin_month'=>$vn['begin_month'],
                                                        'begin_day'=>$vn['begin_day'],
                                                        'begin_night'=>2,
                                                        'type'=>$vn['type'],
                                                        'is_meeting'=>$vn['is_meeting'],
                                                        'bid'=>$vn['bid'],
                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day']
                                                    ];
                                                }
                                               
                                                $a = 1;
                                                for ($i=1; $i <=$d; $i++) {
                                                    $day = $vn['begin_day'] + $i;
            
                                                    if($day > $days){
                                                        if($vn['begin_month'] == 12){
                                                            if($a < 10){
                                                                $as = '0' . $a;
                                                            }
                                                            // $as = strval($a);
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['end_year'],
                                                                'begin_month'=>$vn['end_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>1,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                                'day'=>$vn['end_year'] . '-' . $vn['end_month'] . '-' . $as
                
                                                            ];
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['end_year'],
                                                                'begin_month'=>$vn['end_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>2,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                            'day'=>$vn['end_year'] . '-' . $vn['end_month'] . '-' . $as
                
                                                            ];
                                                            $a++;

                                                        }else{
                                                            if($a < 10){
                                                                $as = '0' . $a;
                                                            }
                                                            // $as = strval($a);
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['begin_year'],
                                                                'begin_month'=>$vn['end_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>1,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                                'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                
                                                            ];
                                                            $newArrs[] =[
                                                                'id'=>$vn['id'],
                                                                'begin_year'=>$vn['begin_year'],
                                                                'begin_month'=>$vn['end_month'],
                                                                'begin_day'=>$as,
                                                                'begin_night'=>2,
                                                                'type'=>$vn['type'],
                                                                'is_meeting'=>$vn['is_meeting'],
                                                                'bid'=>$vn['bid'],
                                                            'day'=>$vn['begin_year'] . '-' . $vn['end_month'] . '-' . $as
                
                                                            ];
                                                            $a++;
                                                        }
                                                       
                                                    }else{
                                                        $newArrs[] =[
                                                            'id'=>$vn['id'],
                                                            'begin_year'=>$vn['begin_year'],
                                                            'begin_month'=>$vn['begin_month'],
                                                            'begin_day'=>strval($vn['begin_day'] + $i),
                                                            'begin_night'=>1,
                                                            'type'=>$vn['type'],
                                                            'is_meeting'=>$vn['is_meeting'],
                                                            'bid'=>$vn['bid'],
                                                        'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
            
                                                        ];
                                                        $newArrs[] =[
                                                            'id'=>$vn['id'],
                                                            'begin_year'=>$vn['begin_year'],
                                                            'begin_month'=>$vn['begin_month'],
                                                            'begin_day'=>strval($vn['begin_day'] + $i),
                                                            'begin_night'=>2,
                                                            'type'=>$vn['type'],
                                                            'is_meeting'=>$vn['is_meeting'],
                                                            'bid'=>$vn['bid'],
                                                            'day'=>$vn['begin_year'] . '-' . $vn['begin_month'] . '-' . strval($vn['begin_day'] + $i)
            
                                                        ];
                                                    }
                                                }
                                                foreach ($newArrs as $nk => $nv) {
                                                    if($month != $nv['begin_month']){
                                                        unset($newArrs[$nk]);
                                                    }
                                                }
                                            }
                                            $vn['day'] = $vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day'];
                                            unset($vn['end_year']);
                                            unset($vn['end_month']);
                                            unset($vn['end_day']);
                                            unset($vn['end_night']);
                                            $newArrs = [];
                                        }
                                    }
                                }else{
                                    $vn['day'] = $vn['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day'];
                                    unset($vn['end_year']);
                                    unset($vn['end_month']);
                                    unset($vn['end_day']);
                                    unset($vn['end_night']);
                                    $newArrs = [];
                                }
                                if(isset($newArrd[$fk][$kn][$vk])){
                                    $new_arrs[] = $vn;
                                }else{
                                    $new_arrs = [];
                                }
                                foreach ($new_arrs as $nk => $nv) {
                                  
                                    if($month != $nv['begin_month']){
                                        unset($new_arrs[$nk]);
                                    }
                                    if(isset($nv['end_year'])){
                                        $new_arrs[$nk]['day'] = $nv['begin_year'] . '-' . $vn['begin_month'] . '-' . $vn['begin_day'];
                                        unset($new_arrs[$nk]['end_year']);
                                        unset($new_arrs[$nk]['end_month']);
                                        unset($new_arrs[$nk]['end_day']);
                                        unset($new_arrs[$nk]['end_night']);
                                    }
                                }
                                $resa[] = array_merge($newArrs,$new_arrs);
                                $new_arrs = [];
                            }
                        }
                    }
                    $aa = [];
                    foreach ($resa  as $ak => $av) {
                        $aa = array_merge($av,$aa);
                    }

                    $banquet[$kb]['order'] = $aa;
                    $resa = [];
                    $new_arrs = [];
                }
                
            }
            // 数组排序
        $temArr=array();
        foreach($banquet as $key=>$value){
            if($value['id'] == $banquets){
                $temArr[]=$value;
                unset($banquet[$key]);
            }
        }
        $resArr=array_merge($temArr,$banquet);
        }else{
            $resArr = $banquet;
        }

        $data['list'] = $resArr;                                 
        return $this->ajaxReturn(0,'成功',$data);
    }
    public function group_same_key($arr,$key)
    {
        $new_arr = array();
         foreach($arr as $k=>$v ){
            $new_arr[$v[$key]][] = $v;
        }
        return $new_arr;
    }

    /**
     * @title 查看潜客信息
     * @description 接口说明
     * @header name:flag require:1 default: desc:手机设备号
     * @author 开发者
     * @url /api/Index/latent
     * @method POST
     * @param name:id type:int require:1 default: other: desc:宴会厅id
     * @param name:year type:string require:1 default: other: desc:年份
     * @param name:month type:string require:1 default: other: desc:月份
     * @param name:day type:string require:1 default: other: desc:日期
     * @param name:begin_night type:int require:1 default: other: desc:1上午2下午
     *
     * @return list:列表@
     * @list book:客户姓名 addtime:预定时间 t_name:宴会类型 director:客户经理 type:1个人客户2他人客户
     * @return banquet:宴会@
     * @banquet name:宴会名 time:宴会时间
     */
    public function latent()
    {
        $user = $this->user;
        if(!input('year')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        if(!input('month')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        if(!input('day')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        if(!input('id')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        $year = input('year');
        $month = input('month');
        $begin_day = input('day');
        $id = input('id');
        $begin_night = input('begin_night');


        $where[] = ['begin_year','=',$year];
        $where[] = ['begin_month','=',$month];
        $where[] = ['begin_day','=',$begin_day];
        $where[] = ['hid','=',$user['hid']];
        $where[] = ['type','neq',3];
        $where[] = ['bid','=',$id];
        $where[] = ['is_meeting','=',2];
        $where[] = ['is_del','=',2];
        $where[] = ['begin_night','=',$begin_night];
        $list = db::name('scheduled')->where($where)
        ->field('id,t_name,begin_night,book,addtime,director_id,type,is_meeting')
        ->order('addtime desc')
        ->select();



        $wheres[] = ['bid','=',$id];
        $wheres[] = ['type','neq',3];
        $wheres[] = ['is_meeting','=',1];
        $wheres[] = ['is_del','=',2];
        $meeting = db::name('scheduled')->where($wheres)
        ->field('id,t_name,begin_night,book,addtime,director_id,type,begin_year,begin_month,begin_day,begin_night
        ,end_year,end_month,end_day,end_night')
        ->select();
        $begin = $year . '-' . $month . '-' . $begin_day;
        $begin = strtotime($begin);
        if($meeting){
            $newArr = [];
            foreach($meeting as $ks=>$vs){
                $begins = $vs['begin_year'] . '-' . $vs['begin_month'] . '-' .$vs['begin_day'];
                $ends = $vs['end_year'] . '-' . $vs['end_month'] . '-' .$vs['end_day'];
                $begins = strtotime($begins);
                $ends = strtotime($ends);
                if($begin>=$begins && $begin<=$ends){
                    $newArr['id'] = $vs['id'];
                    $newArr['t_name'] = $vs['t_name'];
                    $newArr['type'] = $vs['type'];
                    $newArr['begin_night'] = $vs['begin_night'];
                    $newArr['book'] = $vs['book'];
                    $newArr['addtime'] = $vs['addtime'];
                    $newArr['director_id'] = $vs['director_id'];
                    $newArrs[] = $newArr;
                }

            }
            $list = array_merge($list,$newArrs);
        }
        $banquet['name'] = db::name('banquet')->where('id',$id)
        ->value('name');
        $banquet['time'] = $year.'-'.$month.'-'.$begin_day;

        foreach ($list as $ks => $vs) {
            if($vs['type'] == 1){
                $is_del = 1;
            }
            if($vs['type'] == 2){
                $is_del = 2;
                break;
            }
        }

        foreach ($list as $k => $v) {

            // if($v['type'] == 2){
            //     return $this->ajaxReturn(1,'此宴会厅已有预定');die;
            // }


            if($v['type'] == 2){
                $list[$k]['is_del'] = 1; 
            }elseif($v['type'] == 1){
                $list[$k]['is_del'] = $is_del; 
            }


            $users = db::name('user')->where('id',$v['director_id'])->field('id,username')->find();
            $list[$k]['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
            $list[$k]['director'] = urldecode($users['username']);
            if($v['director_id'] == $user['id']){
                $list[$k]['type'] = 1;
            }else{
                $list[$k]['type'] = 2;
            }
            unset($list[$k]['director_id']);
        }
        $data['list'] = $list;
        $data['banquet'] = $banquet;
        return $this->ajaxReturn(0,'成功',$data);
    }
    /**
     * @title 查看潜客预定信息（暂时不用，用修改订单获取数据）
     * @description 接口说明
     * @header name:flag require:1 default: desc:手机设备号
     * @author 开发者
     * @url /api/Index/latent_del
     * @method POST
     * @param name:id type:int require:1 default: other: desc:预定id
     *
     * @return list:列表@
     * @list begin_time:宴会时间 is_meeting:1会议2宴会 end_time:会议结束时间（宴会类型无此参数） b_name:宴会厅 t_name:宴会类型 desk:桌数 prepare_desk:备桌 d_money:餐标金额 book:预订人 mobile:预订人手机号 sex:1男2女 increase_money:增值金额 director:客户经理 source:客户来源 addtime:预定时间 content:备注 contract:合同 other:其他信息
     */
    public function latent_del()
    {
        $user = $this->user;
        if(!input('id')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        $id = input('id');
        $where[] = ['id','=',$id];
        $where[] = ['director_id','=',$user['id']];
        $list = db::name('scheduled')->where($where)
        ->field('id,b_name,t_name,begin_year,begin_month,begin_day,begin_night,end_year,end_month,
        end_day,end_night,book,mobile,sex,d_money,increase_money,source,addtime,other,contract,
        content,is_meeting,desk,prepare_desk')
        ->find();
        if(!$list){
            return $this->ajaxReturn(1,'不可操作他人订单');
        }
        if($list['begin_night'] == 1){
            $list['begin_night'] = '中午';
        }else{
            $list['begin_night'] = '下午';
        }
        if($list['end_night'] == 1){
            $list['end_night'] = '中午';
        }else{
            $list['end_night'] = '下午';
        }
        $list['begin_time'] = $list['begin_year'] . '年' . $list['begin_month'] . '月' . $list['begin_day'] . '日' . $list['begin_night'] ;
        if($list['is_meeting'] == 1){
            $list['end_time'] = $list['end_year'] . '年' . $list['end_month'] . '月' . $list['end_day'] . '日' . $list['end_night'] ;
        }else{
            // $list['end_time'] = '';
        }
        $list['source'] = db::name('source')->where('id',$list['source'])->value('name');
        $list['addtime'] = date('Y-m-d H:i:s',$list['addtime']);
        $image = explode( ",",$list['contract']);
        $images = explode( ",",$list['other']);

        if(count($image) != 1){
            $pic = array();
            foreach($image as $vs){
                $pic[] = get_file_path($vs);
            }
            $list['contract'] = $pic;
        }else{
            $pics = array();
            $pics[] = get_file_path($list['contract']);
            $list['contract'] = $pics;
        }

        if(count($images) != 1){
            $pic = array();
            foreach($image as $vs){
                $pic[] = get_file_path($vs);
            }
            $list['other'] = $pic;
        }else{
            $pics = array();
            $pics[] = get_file_path($list['other']);
            $list['other'] = $pics;
        }
        unset($list['begin_year']);
        unset($list['begin_month']);
        unset($list['begin_day']);
        unset($list['begin_night']);
        unset($list['end_year']);
        unset($list['end_month']);
        unset($list['end_day']);
        unset($list['end_night']);
        $data['list'] = $list;
        return $this->ajaxReturn(0,'成功',$data);
    }
    /**
     * @title 删除订单
     * @description 接口说明
     * @header name:flag require:1 default: desc:手机设备号
     * @author 开发者
     * @url /api/Index/latent_delete
     * @method POST
     * @param name:id type:int require:1 default: other: desc:id
     *
     */
    public function latent_delete()
    {
        $user = $this->user;
        if(!input('id')){
            return $this->ajaxReturn(1,'缺少参数');
        }
        $id = input('id');
        $where[] = ['id','=',$id];
        $order = db::name('scheduled')->where($where)->find();
        if(!$order){
            return $this->ajaxReturn(1,'订单异常');
        }

        if($order['director_id'] != $user['id']){
            $pid = db::name('admin_role')->where('id','in',$user['role'])->field('pid')->select();
            $pids = 0;
            foreach ($pid as $vs) {
                if($vs['pid'] == 0){
                    $pids = 1;
                    break;
                }else{
                    $pids = 2;
                }
            }
            if($pids == 2){
                $res = RoleModel::roleAuth($user['role']);
                $newArrs = [];
                if($res){
                    foreach ($res as $k => $v) {
                        $str1 =str_replace("[","",$res[$k]);
                        $str1 =str_replace("]","",$str1);
                        $newArr = explode(',',$str1);
                        $newArrs = array_merge($newArr,$newArrs);
                    }
                    foreach ($newArrs as $kn => $vn) {
                        $vn =str_replace('"',"",$vn);
                        $newArrs[$kn] = $vn;
                    }
                    if(!in_array('303',$newArrs)){
                        return $this->ajaxReturn(1,'暂无权限');
                    }
                }
            } 
        }
        



        db::name('scheduled')->where($where)->update(['is_del'=>1]);
        return $this->ajaxReturn(0,'成功');
    }
     /**
     * @title 宴会厅
     * @description 接口说明
     * @header name:flag require:1 default: desc:手机设备号
     * @author 开发者
     * @url /api/Index/scheduled
     * @method POST
     *
     * @return list:列表@
     * @list id:id name:宴会厅名称  max:宴会厅最大桌数 excellent:最优桌数 
     */
    public function scheduled()
    {
        $user = $this->user;
        $where[] = ['hid','=',$user['hid']];
        $where[] = ['is_hidden','=',1];
        $where[] = ['is_del','=',1];
        $list = db::name('banquet')->where($where)->field('name,id,max,excellent')->select();
        if($list){
            return $this->ajaxReturn(0,'成功',$list);
        }
    }


}